-
Notifications
You must be signed in to change notification settings - Fork 384
[cronet] Support aborting requests #1797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Package publishing
Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation. |
PR Health
Breaking changes
|
Package | Change | Current Version | New Version | Needed Version | Looking good? |
---|---|---|---|---|---|
cronet_http | Breaking | 1.4.0 | 1.5.0-wip | 2.0.0 Got "1.5.0-wip" expected >= "2.0.0" (breaking changes) |
This check can be disabled by tagging the PR with skip-breaking-check
.
Changelog Entry ✔️
Package | Changed Files |
---|
Changes to files need to be accounted for in their respective changelogs.
Coverage ⚠️
File | Coverage |
---|---|
pkgs/cronet_http/example/integration_test/client_profile_test.dart | 💔 Not covered |
pkgs/cronet_http/example/integration_test/client_test.dart | 💔 Not covered |
pkgs/cronet_http/lib/src/cronet_client.dart | 💔 Not covered |
pkgs/cronet_http/lib/src/jni/jni_bindings.dart | 💔 Not covered |
This check for test coverage is informational (issues shown here will not fail the PR).
This check can be disabled by tagging the PR with skip-coverage-check
.
API leaks ✔️
The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.
Package | Leaked API symbols |
---|
License Headers ✔️
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
Files |
---|
no missing headers |
All source files should start with a license header.
Unrelated files missing license headers
Files |
---|
pkgs/http/example/main.dart |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -345,6 +345,29 @@ jb.UrlRequestCallbackProxy$UrlRequestCallbackInterface _urlRequestCallbacks( | |||
} | |||
jByteBuffer?.release(); | |||
}, | |||
// Will always be the last callback invoked. | |||
// See https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/UrlRequest#cancel() | |||
onCanceled: (urlRequest, urlResponseInfo) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mention that urlResponseInfo
can actually be null (since right now everything is nullable).
Optional: consider using _
for the unused parameters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. I'm leaving the argument names since having comments for underscore looks weird.
Revisions updated by `dart tools/rev_sdk_deps.dart`. ai (https://github.com/dart-lang/ai/compare/40607dc..7fbe88a): 7fbe88a 2025-07-25 Jacob MacDonald refine the prompt and fix the extension listener (dart-lang/ai#244) 8d2384b 2025-07-25 Jacob MacDonald add some intellij files to gitignore (dart-lang/ai#245) e09e469 2025-07-24 Jacob MacDonald add prompt for using flutter driver to write a test for a user journey (dart-lang/ai#243) 88d7a4d 2025-07-23 Jacob MacDonald Flutter driver updates, add screenshot support back (dart-lang/ai#241) http (https://github.com/dart-lang/http/compare/4a90d16..afda310): afda310 2025-07-23 Brian Quinlan [cronet] Support aborting requests (dart-lang/http#1797) test (https://github.com/dart-lang/test/compare/c201cc9..6aeb1e4): 6aeb1e4f 2025-07-24 Nate Bosch Consider NaN a match for itself (dart-lang/test#2524) 65a37698 2025-07-23 Nate Bosch Use latest analyzer and language version (dart-lang/test#2523) web (https://github.com/dart-lang/web/compare/767151e..da1dd5d): da1dd5d 2025-07-24 Devon Carew switch CI to using workflow files (dart-lang/web#428) 8ffaf5e 2025-07-23 Nikechukwu [interop] Implement Diagnostics and Handling Errors (dart-lang/web#426) Change-Id: I499491c4c1466cb1c81cf5e4bbff4a484e880e57 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/442560 Auto-Submit: Devon Carew <[email protected]> Commit-Queue: Devon Carew <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
New versions of `http`, `cronet_http`, and `cupertino_http` support request cancellation (just like the `HttpClient` from `dart:io`). Minor change to use `AbortableRequest` and pass the `cancelFuture` to the `abortTrigger` argument. ### Additional context and info (if any) - [Add request cancellation to cupertino_http](dart-lang/http#1779) - [[cronet] Support aborting requests](dart-lang/http#1797) - [feat: support aborting HTTP requests](dart-lang/http#1773) ### Testing with ASP.NET Core API Test Flutter app (Android and iOS only): https://github.com/zzyzy/dio_lzz_fork_flutter/blob/main/lib/test_dio_request_cancellation.dart Test API endpoint: ```csharp [HttpGet("request-cancellation")] public async Task<IActionResult> TestRequestCancellation(CancellationToken cancellationToken) { try { _logger.LogInformation("Request started {RequestID} {Platform}", HttpContext.TraceIdentifier, Request.Headers["X-App-Platform"]); await Task.Delay(TimeSpan.FromMinutes(5), cancellationToken); _logger.LogInformation("Request end {RequestID} {Platform}", HttpContext.TraceIdentifier, Request.Headers["X-App-Platform"]); } catch (TaskCanceledException) { _logger.LogInformation("Request canceled {RequestID} {Platform}", HttpContext.TraceIdentifier, Request.Headers["X-App-Platform"]); // Do nothing } return Ok(); } ``` #### Android Before: ``` info: Microsoft.Hosting.Lifetime[14] Now listening on: http://0.0.0.0:5292 info: Microsoft.Hosting.Lifetime[0] Application started. Press Ctrl+C to shut down. info: Microsoft.Hosting.Lifetime[0] Hosting environment: Development info: Microsoft.Hosting.Lifetime[0] Content root path: D:\ws\me\repos\my-code-vault\MyToolkit\TestAspNetCoreWebApi info: TestAspNetCoreWebApi.Controllers.TestController[0] Request started 0HNEMB51JJSG7:00000001 Android info: TestAspNetCoreWebApi.Controllers.TestController[0] Request started 0HNEMB51JJSG8:00000001 Android info: TestAspNetCoreWebApi.Controllers.TestController[0] Request started 0HNEMB51JJSG9:00000001 Android info: TestAspNetCoreWebApi.Controllers.TestController[0] Request started 0HNEMB51JJSGA:00000001 Android info: TestAspNetCoreWebApi.Controllers.TestController[0] Request started 0HNEMB51JJSGB:00000001 Android info: TestAspNetCoreWebApi.Controllers.TestController[0] Request started 0HNEMB51JJSGC:00000001 Android ``` After: ``` info: Microsoft.Hosting.Lifetime[14] Now listening on: http://0.0.0.0:5292 info: Microsoft.Hosting.Lifetime[0] Application started. Press Ctrl+C to shut down. info: Microsoft.Hosting.Lifetime[0] Hosting environment: Development info: Microsoft.Hosting.Lifetime[0] Content root path: D:\ws\me\repos\my-code-vault\MyToolkit\TestAspNetCoreWebApi info: TestAspNetCoreWebApi.Controllers.TestController[0] Request started 0HNEMAV9NHQ97:00000001 Android info: TestAspNetCoreWebApi.Controllers.TestController[0] Request canceled 0HNEMAV9NHQ97:00000001 Android info: TestAspNetCoreWebApi.Controllers.TestController[0] Request started 0HNEMAV9NHQ98:00000001 Android info: TestAspNetCoreWebApi.Controllers.TestController[0] Request canceled 0HNEMAV9NHQ98:00000001 Android info: TestAspNetCoreWebApi.Controllers.TestController[0] Request started 0HNEMAV9NHQ99:00000001 Android info: TestAspNetCoreWebApi.Controllers.TestController[0] Request canceled 0HNEMAV9NHQ99:00000001 Android info: TestAspNetCoreWebApi.Controllers.TestController[0] Request started 0HNEMAV9NHQ9A:00000001 Android ``` #### IOS Before: ``` info: Microsoft.Hosting.Lifetime[14] Now listening on: http://0.0.0.0:5292 info: Microsoft.Hosting.Lifetime[0] Application started. Press Ctrl+C to shut down. info: Microsoft.Hosting.Lifetime[0] Hosting environment: Development info: Microsoft.Hosting.Lifetime[0] Content root path: D:\ws\me\repos\my-code-vault\MyToolkit\TestAspNetCoreWebApi info: TestAspNetCoreWebApi.Controllers.TestController[0] Request started 0HNEMB42PERN4:00000001 IOS info: TestAspNetCoreWebApi.Controllers.TestController[0] Request started 0HNEMB42PERN5:00000001 IOS info: TestAspNetCoreWebApi.Controllers.TestController[0] Request started 0HNEMB42PERN6:00000001 IOS info: TestAspNetCoreWebApi.Controllers.TestController[0] Request started 0HNEMB42PERN7:00000001 IOS info: TestAspNetCoreWebApi.Controllers.TestController[0] Request started 0HNEMB42PERN8:00000001 IOS info: TestAspNetCoreWebApi.Controllers.TestController[0] Request started 0HNEMB42PERN9:00000001 IOS ``` After: ``` info: Microsoft.Hosting.Lifetime[14] Now listening on: http://0.0.0.0:5292 info: Microsoft.Hosting.Lifetime[0] Application started. Press Ctrl+C to shut down. info: Microsoft.Hosting.Lifetime[0] Hosting environment: Development info: Microsoft.Hosting.Lifetime[0] Content root path: D:\ws\me\repos\my-code-vault\MyToolkit\TestAspNetCoreWebApi info: TestAspNetCoreWebApi.Controllers.TestController[0] Request started 0HNEMB35NC5L0:00000001 IOS info: TestAspNetCoreWebApi.Controllers.TestController[0] Request canceled 0HNEMB35NC5L0:00000001 IOS info: TestAspNetCoreWebApi.Controllers.TestController[0] Request started 0HNEMB35NC5L1:00000001 IOS info: TestAspNetCoreWebApi.Controllers.TestController[0] Request canceled 0HNEMB35NC5L1:00000001 IOS info: TestAspNetCoreWebApi.Controllers.TestController[0] Request started 0HNEMB35NC5L2:00000001 IOS info: TestAspNetCoreWebApi.Controllers.TestController[0] Request canceled 0HNEMB35NC5L2:00000001 IOS info: TestAspNetCoreWebApi.Controllers.TestController[0] Request started 0HNEMB35NC5L3:00000001 IOS info: TestAspNetCoreWebApi.Controllers.TestController[0] Request canceled 0HNEMB35NC5L3:00000001 IOS info: TestAspNetCoreWebApi.Controllers.TestController[0] Request started 0HNEMB35NC5L4:00000001 IOS info: TestAspNetCoreWebApi.Controllers.TestController[0] Request canceled 0HNEMB35NC5L4:00000001 IOS info: TestAspNetCoreWebApi.Controllers.TestController[0] Request started 0HNEMB35NC5L5:00000001 IOS ``` --------- Signed-off-by: Zhen Zhi Lee <[email protected]> Co-authored-by: zhenzhi.lee <[email protected]> Co-authored-by: Alex Li <[email protected]>
Contribution guidelines:
dart format
.Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.